<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core_1_1" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>我的钱包</title>
    <link href="${applicationScope.basePath}/css/bootstrap.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="${applicationScope.basePath}/css/index.css">
    <script src="${applicationScope.basePath}/js/jquery-3.4.1.min.js"></script>
    <script src="${applicationScope.basePath}/js/bootstrap.min.js"></script>
    <link rel="stylesheet" type="text/css" href="${applicationScope.basePath}/css/model.css">
    <link rel="stylesheet" type="text/css" href="${applicationScope.basePath}/css/userhome.css">
</head>
<body>
<jsp:include page="../header.jsp" flush="true"/>
<div class="container" style="margin-top: 80px;">
    <!--
        描述：左侧个人中心栏
    -->
    <div class="row">
        <div class="col-md-2">
            <div class="row">
                <div class="col-md-12">
                    <div class="thumbnail">
                        <img src="${applicationScope.basePath}/images/header.jpg" alt="" class=""
                             style="border-radius: 50%;width: 140px;height: 140px;">
                        <div class="caption">
                            <h3 style="text-align: center;">${requestScope.user.userName}</h3>
                        </div>
                        <hr>
                        <a id="myWallet" class="btn btn btn-warning btn-block"
                           href="${applicationScope.basePath}/user/space/purse">我的钱包：${requestScope.purse.balance}元</a>
                        <span disabled="true" class="btn btn-warning btn-block" data-toggle="modal"
                              data-target="#myModal"
                              style="margin-top: 15px;">我的信用积分：${requestScope.user.power}</span>
                    </div>
                </div>
            </div>
            <div class="list-group ">
                <a id="orders" href="${applicationScope.basePath}/user/space/orders" class="list-group-item list-group-item-info ">订单中心 </a>
                <a id="notice_list" href="${applicationScope.basePath}/user/space" class="list-group-item list-group-item-info">求购中心<span
                        class="badge">${requestScope.num}</span></a>
                <a id="system_msg" href="${applicationScope.basePath}/user/space/sys" class="list-group-item list-group-item-info">系统信息<span
                        class="badge">${requestScope.sys}</span></a>
                <a id="goods_list" href="${applicationScope.basePath}/user/space/goods" class="list-group-item list-group-item-info">我的商品</a>
                <a id="person_msg" href="${applicationScope.basePath}/user/space/msg"
                   class="list-group-item list-group-item-info">个人设置</a>
            </div>
        </div>
        <!--
            描述：右侧个人内容栏
        -->
        <div class="col-md-10">
            <div id="content1">
                <h4>我的钱包</h4>
                <hr/>
                <div class="row" style="margin: 0 auto;width: 50%;">
                    <div class="col-md-12">
                        <div class="thumbnail">
                            <img src="${applicationScope.basePath}/images/myWallet.jpg" alt="...">
                            <div class="caption" style="height: 230px;">
                                <div class="form-horizontal">
                                    <div class="form-group">
                                        <label for="balance" class="col-sm-2 control-label">余额</label>
                                        <div class="col-sm-10">
                                            <input type="text" name="balance" class="form-control" disabled id="balance"
                                                   value="${requestScope.purse.balance}" placeholder="">
                                        </div>
                                    </div>
                                    <form enctype='multipart/form-data' id="myUpAndDwon1"
                                          action="${applicationScope.basePath}/user/space/purse" method="post"
                                          class="form-horizontal">
                                        <div class="form-group">
                                            <label for="charge" class="col-sm-2 control-label">充值</label>
                                            <div class="col-sm-10">
                                                <input type="number" name="recharge" class="form-control" id="charge"
                                                       placeholder="">
                                            </div>
                                        </div>
                                    </form>
                                    <form enctype='multipart/form-data' id="myUpAndDwon2"
                                          action="${applicationScope.basePath}/user/space/purse" method="post"
                                          class="form-horizontal">
                                        <div class="form-group">
                                            <label for="cashout" class="col-sm-2 control-label">提现</label>
                                            <div class="col-sm-10">
                                                <input type="number" name="withdrawals" class="form-control"
                                                       id="cashout"
                                                       placeholder="">
                                            </div>
                                        </div>
                                    </form>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label"></label>
                                        <div class="col-sm-10" style="text-align: center;">
                                            <c:if test="${requestScope.purse.recharge.status==1 || requestScope.purse.recharge.status==2 || requestScope.purse.recharge.status == null}">
                                                <button form="myUpAndDwon1" type="submit" id="upAnddown1"
                                                        onclick="upAnddown(1);"
                                                        class="btn btn-danger">立即充值
                                                </button>
                                            </c:if>
                                            <c:if test="${requestScope.purse.withdrawals.status==1 || requestScope.purse.withdrawals.status==2 || requestScope.purse.recharge.status == null}">
                                                <button form="myUpAndDwon2" type="submit" id="upAnddown2"
                                                        onclick="upAnddown(2);"
                                                        class="btn btn-danger">立即提现
                                                </button>
                                            </c:if>
                                            <c:if test="${requestScope.purse.recharge.status == 0}">
                                                <button disabled class="btn btn-danger">【充值审核中】</button>
                                            </c:if>
                                            <c:if test="${requestScope.purse.withdrawals.status == 0}">
                                                <button disabled class="btn btn-danger">【体现审核中】</button>
                                            </c:if>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="${applicationScope.basePath}/js/jquery.form.min.js"></script>
<script type="text/javascript">
    let options;
    let options2;
    $(function () {

        options = {
            success: function (data) {
                if (!data['flag']) {
                    $("#upAnddown1").text("【充值审核中】");
                    location.href = "${applicationScope.basePath}/alipay/gopay?orderId=" + data.datas.orderId;
                } else{
                    alert(data['errorMsg']);
                }
            }
        };
        $("#myUpAndDwon1").ajaxForm(options);

        options2 = {
            success: function (data) {
                if (!data['flag']) {
                    $("#upAnddown2").text("【体现审核中】");
                } else {
                    alert(data['errorMsg']);
                }
            }
        };
        $("#myUpAndDwon2").ajaxForm(options2);

    });

    function upAnddown(num) {
        let reg = /^[1-9]\d*$|^0$/;
        /*充值*/
        if (num === 1) {
            let Recharge = $(" input[ name='recharge' ] ").val();
            if (Recharge == null || Recharge === "") {
                alert("请输入您要充值的金额！")
            } else if (reg.test(Recharge) !== true) {
                alert("您输入的金额格式有误，请重新输入！")
            } else {
                $("#upAnddown1").button("loading");
            }
        }
        if (num === 2) {
            let withdrawals = $(" input[ name='withdrawals' ] ").val();
            if (withdrawals == null || withdrawals === "") {
                alert("请输入您要体现的金额！")
            } else if (reg.test(withdrawals) !== true) {
                alert("您输入的金额格式有误，请重新输入！")
            } else {
                $("#upAnddown2").button("loading");
            }
        }
    }
</script>
</body>
</html>
